/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.Ufes.exeSwing.Persistence;

import edu.Ufes.exeSwing.Model.Conta;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.TreeSet;

/**
 *
 * @author bhetynnacatalunha
 */
public class ContaPersistence {
     public boolean salvarConta(TreeSet<Conta> pContas){

        boolean retorno = false;

        try {
            FileOutputStream arquivoConta = new FileOutputStream("data/Conta.pas");
            ObjectOutputStream ooConta = new ObjectOutputStream(arquivoConta);
            ooConta.writeObject(pContas);
            ooConta.close();
            retorno = true;

        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
        return retorno;

    }
    
    public TreeSet<Conta> recuperarContas(){
    
        TreeSet<Conta> contas = new TreeSet<Conta>();
        
        try{
            File arquivoConta = new File("data/Conta.pas");
            FileInputStream fiConta = new FileInputStream(arquivoConta.getAbsolutePath());
            ObjectInputStream oiConta = new ObjectInputStream(fiConta);
            contas = (TreeSet<Conta>) oiConta.readObject();
            oiConta.close();
        }catch(Exception e){
            System.err.println(e.getMessage());
        }
        return contas;
    }
    
    
}
